package com.platform.core.web.controller;

import com.platform.comm.web.results.DataJsonResult;
import com.platform.comm.web.results.JsonResult;
import com.platform.comm.web.results.PageListJsonResult;
import com.platform.core.service.NcloudSysNotifyBiz;
import com.platform.dto.NcloudSysNotifyDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 通知公告
 * @author zq
 */
@Api(tags = "公告管理")
@RestController
@RequestMapping(name = "公告管理", path = "/management/notify")
public class SysNotifyController extends BaseController{

    private final NcloudSysNotifyBiz sysNotifyBiz;

    @Autowired
    public SysNotifyController(NcloudSysNotifyBiz sysNotifyBiz) {
        this.sysNotifyBiz = sysNotifyBiz;
    }

    /**
     * 新增公告
     */
    @ApiOperation("新增公告")
    @PostMapping(name = "新增公告", path = "/create")
    public JsonResult create(@RequestBody NcloudSysNotifyDto sysNotifyDto) {
        return createOrModifyWithResult(sysNotifyBiz::add, sysNotifyDto);
    }

    /**
     * 删除
     */
    @ApiOperation("删除公告")
    @PostMapping(name = "删除", path = "/deleteById")
    public JsonResult deleteById(@RequestBody Map<String, String> map) {
        sysNotifyBiz.deleteById(map);
        return JsonResult.success();
    }

    /**
     * 发布公告
     */
    @ApiOperation("发布公告")
    @PostMapping(name = "发布公告", path = "/publish")
    public JsonResult publish(@RequestBody Map<String, String> map) {
        sysNotifyBiz.publish(map);
        return JsonResult.success();
    }

    @PostMapping(name = "修改公告", path = "modify")
    @ApiOperation("修改公告")
    public JsonResult modify(@RequestBody  NcloudSysNotifyDto sysNotifyDto) {
        return createOrModifyWithResult(sysNotifyBiz::modify, sysNotifyDto);
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页查询通知公告")
    @PostMapping(name = "分页查询", path = "/search")
    public PageListJsonResult<NcloudSysNotifyDto> search(@RequestBody Map<String, String> map) {
        Page<NcloudSysNotifyDto> entities = sysNotifyBiz.search(map,getPageable(map));
        return new PageListJsonResult<>(entities);
    }

    /**
     * 记录详情
     */
    @ApiOperation("公告详情")
    @PostMapping(name = "公告详情", path = "/detail")
    public DataJsonResult<NcloudSysNotifyDto> detail(@RequestBody Map<String, String> map) {
        NcloudSysNotifyDto entities = sysNotifyBiz.detail(MapUtils.getString(map,"id",""));
        return DataJsonResult.succeed(entities);
    }

}
